﻿using Common.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.IO {

  public class FileInfoEx {

    private string fileName;
    private string volumeNumber;
    private string rootPath;
    private string directory;
    private string fullPath;
    private Int64 isDirectory = 0;
    private string scanTime;
    private string md5;

    public FileInfoEx() {

    }

    public FileInfoEx(FileInfo file) {
      this.ConstructFileInfoEx(file);
    }


    public FileInfoEx(string filePath) {
      FileInfo file = new FileInfo(filePath);
      this.ConstructFileInfoEx(file);
    }

    private void ConstructFileInfoEx(FileInfo file) {
      this.fileName = file.Name;
      this.rootPath = file.Directory.Root.Name;
      this.volumeNumber = DiskDriver.GetHardDiskNumberByVolume(this.rootPath.Trim('\\').Trim(':'));
      this.directory = file.Directory.FullName;
      this.fullPath = file.FullName;
      this.isDirectory = 0;
      this.scanTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
      this.md5 = "md5";//MD5Util.GetMD5HashFromFile(this.fullPath);
    }

    public string FileName {
      get {
        return fileName;
      }

      set {
        fileName = value;
      }
    }

    public string VolumeNumber {
      get {
        return volumeNumber;
      }

      set {
        volumeNumber = value;
      }
    }

    public string RootPath {
      get {
        return rootPath;
      }

      set {
        rootPath = value;
      }
    }

    public string Directory {
      get {
        return directory;
      }

      set {
        directory = value;
      }
    }

    public string FullPath {
      get {
        return fullPath;
      }

      set {
        fullPath = value;
      }
    }

    public long IsDirectory {
      get {
        return isDirectory;
      }

      set {
        isDirectory = value;
      }
    }

    public string ScanTime {
      get {
        if (scanTime == null) {
          scanTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
        return scanTime;
      }

      set {
        scanTime = value;
      }
    }

    public string Md5 {
      get {
        return md5;
      }

      set {
        md5 = value;
      }
    }
  }
}

